package com.pyb.java.basemodule;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

import com.pyb.java.commonutil.utils.BitmapCutUtil;

/**
 * Created by gzy on 2019/5/14.
 */

public class LoadingDialog extends ProgressDialog {

    public LoadingDialog(Context context) {
        super(context);
        // 点击提示框外面是否取消提示框
        setCanceledOnTouchOutside(false);
        // 点击返回键是否取消提示框
        setCancelable(true);
        setIndeterminate(true);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.module_dialog_loading);
        ImageView imageView = findViewById(R.id.loading_image);
        ImageView imgCircle = findViewById(R.id.imgCircle);
        imgCircle.setImageBitmap(BitmapCutUtil.toRoundBitmap(BitmapFactory.
                decodeResource(getContext().getResources(), R.mipmap.module_icon)));
        imageView.setBackgroundResource(R.drawable.module_loading_animation);
        // 通过ImageView对象拿到背景显示的AnimationDrawable
        final AnimationDrawable mAnimation = (AnimationDrawable) imageView.getBackground();
        imageView.post(() -> mAnimation.start());
    }
}
